local bawu = fk.CreateSkill{
  name = "hanqing__bawu",
  tags = { Skill.Compulsory, Skill.Combo },
}

Fk:loadTranslationTable{
  ["hanqing__bawu"] = "霸武",
  [":hanqing__bawu"] = "锁定技，连招技（基本牌+伤害牌），你横置并弃置其中一名目标角色一张牌。若你已横置，改为你弃置一张牌并重置。",

  ["#hanqing__bawu-choose"] = "霸武：弃置其中一名目标角色一张牌",
}

bawu:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(bawu.name) and data.card.is_damage_card and data.firstTarget and
      data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[bawu.name]
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player.chained then
      room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = bawu.name,
        cancelable = false,
      })
      if not player.dead and player.chained then
        player:setChainState(false)
      end
    else
      player:setChainState(true)
      if player.dead then return end
      local targets = table.filter(data.use.tos, function (p)
        return not p.dead and not p:isNude()
      end)
      if #targets == 0 then return end
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = bawu.name,
        prompt = "#hanqing__bawu-choose",
        cancelable = false,
      })[1]
      if to == player then
        room:askToDiscard(player, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = bawu.name,
          cancelable = false,
        })
      else
        local card = room:askToChooseCard(player, {
          target = to,
          flag = "he",
          skill_name = bawu.name,
        })
        room:throwCard(card, bawu.name, to, player)
      end
    end
  end,
})

bawu:addEffect(fk.AfterCardUseDeclared, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(bawu.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if player:getMark(bawu.name) > 0 and data.card.is_damage_card then
      data.extra_data = data.extra_data or {}
      data.extra_data.combo_skill = data.extra_data.combo_skill or {}
      data.extra_data.combo_skill[bawu.name] = true
      room:setPlayerMark(player, bawu.name, 0)
      return
    end
    if data.card.type == Card.TypeBasic then
      room:setPlayerMark(player, bawu.name, 1)
    else
      room:setPlayerMark(player, bawu.name, 0)
    end
  end,
})

return bawu
